package com.usian.service.Impl;


import com.usian.mapper.TbUserMapper;
import com.usian.pojo.TbUser;
import com.usian.pojo.TbUserExample;
import com.usian.service.SSOService;
import com.usian.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class SSOServiceImpl implements SSOService{
    @Autowired
    private SSOService ssoService;
    @Autowired
    private TbUserMapper tbUserMapper;

    @Override
    public List<TbUser> selectByExample(TbUserExample example) {
        return null;
    }

    @Override
    public boolean chekUserInof(String checkValue, Integer checkFlag) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();

        if (checkFlag == 1) {
            criteria.andUsernameEqualTo(checkValue);
        } else if (checkFlag == 2) {
            criteria.andPhoneEqualTo(checkValue);
        }

        List<TbUser> list = tbUserMapper.selectByExample(example);
        if (list == null || list.size() == 0) {
            return true;
        }
        return false;
    }
    @Override
    public Integer userRegister(TbUser user) {
        //将密码做加密处理。
        String pwd = MD5Utils.digest(user.getPassword());
        user.setPassword(pwd);
        //补齐数据
        user.setCreated(new Date());
        user.setUpdated(new Date());
        return this.tbUserMapper.insert(user);
    }
}
